/**
 * @Author MrLi
 * @Version 1.0
 * @Date 2023-08-09 10:51:22
 */
package com.cl.erp_2301.controller;

import com.cl.erp_2301.Service.StoreDetailService;
import com.cl.erp_2301.dto.DataDTO;
import com.cl.erp_2301.dto.StoreDTO;
import com.cl.erp_2301.entity.Goods;
import com.cl.erp_2301.entity.Store;
import com.cl.erp_2301.util.Result;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v2")
public class StoreDetailController {

    @Resource
    private StoreDetailService storeDetailService;

    @RequestMapping(value = "/storedetail", method = RequestMethod.GET)
    public Result findAll(
            int page,
            int rows,
            @RequestParam(name = "storeName",required = false,defaultValue = "") String storeName,
            @RequestParam(name = "goodsName",required = false,defaultValue = "") String goodsName, HttpServletRequest request){
        Page<Object> page1 = PageHelper.startPage(page,rows);
            List<StoreDTO> storeDtoList  = storeDetailService.findAll(storeName,goodsName);
            DataDTO data1 = new DataDTO();
            StoreDTO storeDto = new StoreDTO();
            storeDto.setStoreName(storeName);
            storeDto.setGoodsName(goodsName);
            data1.setRows(storeDtoList);
            data1.setTotal(page1.getTotal());
            request.getSession().setAttribute("storeName",storeDto.getStoreName());
            return Result.ok(data1);
    }

    @ResponseBody
    @RequestMapping("/storedetail/goodsList")
    public Result goodsList(){
        List<Goods> goodsList = storeDetailService.goodsList();
        return Result.okRows(goodsList);
    }

    @ResponseBody
    @RequestMapping("/storedetail/storeList")
    public Result storeList(){
        List<Store> storeList = storeDetailService.storeList();
        return Result.okRows(storeList);
    }




}
